<%@ page language="java" contentType="text/html; charset=UTF-8" %>

<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<script src="<c:url value='/resources/js/manage.js'/>"></script>
<c:import url="../../../template/layout.jsp" charEncoding="UTF-8">
    <c:param name="title" value="用户列表"/>
    <c:param name="body">
        <script>
            $(document).ready(
                    function () {
                        var id = $(".id").val();
                        if (id) {

                        }

                    });
        </script>


        <div class="content-title">用户列表
        </div>
        <div class="container"
             style="background-color:#DCEAF4; width:1300px; height:500px;border-radius: 0px 0px 0px 0px;">
            <c:if test="${message!=null}">
                <div class="alert alert-danger" role="alert">${message.msg}</div>
            </c:if>
            <div class="btn-group pull-right" style="margin-bottom:8px;">
                <a class="btn btn-lg btn-primary" href="${pageContext.request.contextPath}/system/user/edit">
                    <span class="glyphicon"></span> 添加用户
                </a>
            </div>
            <p></p>
            <div class="col-sm-5 col-sm-offset-1">
                <form id="searchForm" method="get" action="/system/user/list"
                      name="user">
                    <div class="input-group">
                        <input id="pageNo" name="pageNo" type="hidden" value="${pager.pageNo}"/>
                        <input id="pageSize" name="pageSize" type="hidden" value="${pager.pageSize}"/>


                    </div>
                </form>
            </div>
            <div class="main-content">

                <table class="table">
                    <thead>
                    <tr>
                        <th>用户名</th>
                        <th>手机</th>
                        <th>邮箱</th>
                        <th>真实名称</th>
                        <th>创建时间</th>
                        <th>角色</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${pager.list}" var="user">
                        <%--<s:iterator value="#request.roleList" var="role">--%>
                        <tr class="success">
                            <td>${user.username}</td>
                            <td>${user.mobile}</td>
                            <td>
                                    ${user.email}
                            </td>
                            <td>
                                    ${user.realName}
                            </td>
                            <td>
                                    ${user.createTime}
                            </td>
                            <td>
                                    ${user.viewRoleName}
                            </td>
                            <td>
                                <shiro:hasPermission name="system:*">
                                <button onclick="editUser('<c:url value="/system/user/getUser?id=${user.id}"/>')"
                                        class="btn btn-primary btn-xs"
                                        data-toggle="modal" data-target="#editUser">编辑
                                </button>
                                &nbsp;&nbsp;
                                <button class="btn btn-primary btn-xs"
                                        href="javascript:void(0)" data-toggle="tooltip" title="删除"
                                        onclick="if (confirm('确认要删除本记录吗？此操作将不可恢复！'))
                                                location = '<c:url
                                                value="/system/user/delete?id=${user.id}"/>';
                                                return false;">删除
                                </button>
                                </shiro:hasPermission>
                                <shiro:hasPermission name="shopManager:*">
                                <a href="${pageContext.request.contextPath}/system/agent/add?id=${user.id}" class="btn btn-primary btn-xs">添加为经纪人</a>
                                </shiro:hasPermission>
                            </td>
                        </tr>
                        <%--</s:iterator>--%>
                    </c:forEach>

                    </tbody>
                </table>
            </div>
            <div class="row">
                <div class="col-sm-12">
                    ${pager}
                </div>
            </div>
        </div>
        <script type="text/javascript">

            function editUser(path) {
                $.ajax({
                    url: path,
                    type: 'get',
                    async: true,
                    dataType: 'json',
                    success: function (user) {
                        /*var temp = '<input class="edit_check" type="checkbox" name="permissions" />';
                         $("#edit_per").removeChild(temp);*/

                        $('#edit_username').val(user.username);
                        $('#edit_mobile').val(user.mobile);
                        $('#edit_email').val(user.email);
                        $('#edit_realName').val(user.realName);
                        $('#edit_id').val(user.id);
alert(user.allRoles);
                        $.each(user.allRoles, function (idx, obj) {
                            var inp = '<input class="edit_check" type="checkbox" name="role" value="' + obj.id + '"/>' + '&nbsp;&nbsp;' + obj.rolename;
                            $("#edit_roles").append(inp);
                            if (role.rolename == obj.rolename) {
                            }
                        });
                    }
                });
            }


        </script>
        <%--编辑模态框--%>
        <div class="modal fade" id="editUser" tabindex="-1" role="dialog">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">
                            <span aria-hidden="true">&times;</span>
                            <span class="sr-only">Close</span>
                        </button>
                        <h3 class="modal-title">编辑</h3>
                    </div>
                    <div class="modal-body">
                        <form action="/system/user/edit" method="POST">
                            <div class="form-group">
                                <label class="control-label" for="edit_username">用户名</label>
                                <input type="text" class="form-control" id="edit_username" name="username"
                                       required>
                            </div>
                            <div class="form-group">
                                <label for="edit_mobile">手机</label>
                                <input class="form-control" id="edit_mobile" name="mobile" required/>
                            </div>
                            <div class="form-group">
                                <label class="control-label" for="edit_email">邮箱</label>
                                <input type="text" class="form-control" id="edit_email" name="email" required>
                            </div>
                            <div class="form-group">
                                <label for="edit_realName">真实姓名</label>
                                <input class="form-control" id="edit_realName" name="realName" required/>
                            </div>
                            <div id="edit_per" class="form-group">
                                <label>角色</label>
                            </div>
                            <div class="form-group">
                                <input class="form-control" type="hidden" name="id" id="edit_id"/>
                            </div>
                            <button class="btn btn-primary btn-lg btn-block" type="submit">
                                确定
                            </button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </c:param>
</c:import>
